Skip to content

Forbid requests whose token has no subject claim, instead of failing with 500 - #5984

Merged
ramonsmits merged 1 commit into
masterfrom
fix-missing-subject-claim-forbidden
Oct 19, 2026
Merged

ramonsmits merged 1 commit into
masterfrom
fix-missing-subject-claim-forbidden

Conversation

@ramonsmits

Copy link
Copy Markdown
Member

With role-based authorization enabled, a token without the subject ID claim (sub) or the subject name claim (preferred_username) gets 500 Internal Server Error on every API request. The authorization handler throws because the audit log needs both values. The handler now denies the request with 403 Forbidden, and logs a warning that names the missing claim and the setting that configures it.

  • PermissionVerbHandler fails the requirement and logs a warning, instead of throwing.
  • Remove ClaimsPrinicpalExtensionMethods.RequireClaim. The handler was its only caller.
  • New tests: an admin token without sub or preferred_username is denied every permission.

…g with 500

With role-based authorization enabled, PermissionVerbHandler needs the
subject ID and subject name claims for the authorization audit log. When a
token did not have one of them, the handler threw an
InvalidOperationException, and every request with that token got 500.

The handler now denies the request (403) and logs a warning that names
the missing claim and the setting that configures it.

- Remove ClaimsPrinicpalExtensionMethods.RequireClaim. The handler was its
  only caller.
- New tests: an admin token without sub or preferred_username is denied
  every permission.
@ramonsmits
ramonsmits marked this pull request as ready for review October 12, 2026 06:55
@ramonsmits
ramonsmits merged commit f5ed66a into master Oct 19, 2026
69 of 70 checks passed
@ramonsmits
ramonsmits deleted the fix-missing-subject-claim-forbidden branch October 19, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants